Making seo friendly urls [duplicate] - url

This question already has answers here:
How to create friendly URL in php?
(8 answers)
PHP function to make slug (URL string)
(30 answers)
Closed 4 months ago.
My htaccess is as follows:
RewriteEngine On
RewriteRule ^page/([^/]*)$ index.php?page=$1 [L]
RewriteRule ^jid/([^/]*)$ job-page.php?id=$1 [L]
RewriteRule ^id/([^/]*)$ index.php?id=$1 [L]
RewriteRule ^id/([^/]*)/page/([^/]*)$ index.php?id=$1&page=$2 [L]
RewriteRule ^sitemap-([^-]*)\.xml$ sitemap.php?no=$1 [L]
Prints as:
domain com/jid/1840
and i would like to make it as
domain com/post-title
Can anyone help me please?

Related

simple mod_rewrite problem

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^?(.*) productfilter.php?category=$1 [NC,L]
This rewrite is returning :
category=productfilter.php
can someone point out what I am doing wrong here
In all likelihood, the issue is that the rewritten URL is getting re-rewritten. Rewrite directives, at least in .htaccess context, get re-executed after a URL rewrite. I think what you are trying to accomplish can be done with:
RewriteRule ^productfilter.php - [NC,L]
RewriteRule ^([^/]*)/?$ productfilter.php?category=$1 [NC,L]
The first RewriteRule just declines to rewrite when productfilter.php already starts the path.

htaccess url rewrite issue

I'm successfully rewriting a users profile page thusly:
RewriteRule ^([a-z0-9]+)$ /profile/profile.php?u=$1 [NC]
RewriteRule ^([a-z0-9]+)/$ /profile/profile.php?u=$1 [NC]
so site.com/username was site.com/profile.php?u=username
Easy.
But now.. I'd like to have standard pages n folders like this...
site.com/login
site.com/help
etc... but the site thinks these are usernames... I've added rules to differentiate them but they dont seem to pick up - ie the one below doesnt work..
RewriteRule ^/login/twitter/$ /login/twitter/index.php [NC]
It thinks login is a username.
Any ideas?
Thanks!
You should use conditional rewrites before your RewriteRule to skip over your reserved names and files and folders that already exist on server:
RewriteCond %{REQUEST_URI} !^/reserved1
RewriteCond %{REQUEST_URI} !^/reserved2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
REQUEST_URI is the resource requested in HTTP request line. The first two lines mean that the URI should not start with your reserved names and should skip over /reserved1 and /reserved2
REQUEST_FILENAME is the same as SCRIPT_FILENAME CGI variable and contains the full local filesystem path to the file or directory matching the request.
The last two lines mean to skip real files and directolries that already exist in server.

SEO friendly URLs (.htaccess)

http://www.domain.com/folder/file?x=1&y=2
Change to:
http://www.domain.com/folder/file/1/2/
http://www.domain.com/folder/?x=1
Change to:
http://www.domain.com/folder/1/
I tried:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder/(.*)/$ folder/index.php?x=$1 [L]
RewriteRule ^folder/file/(.*)/(.*)/$ folder/file.php?x=$1&y=$2 [L]
but that doesn't work, does anyone have any idea why?
when i take out the first rule, i can access the second one via:
http://www.domain.com/folder/1/2/
but not:
http://www.domain.com/folder/file/1/2/
god, i hope i am not confusing anyone who is reading this lol i hope it makes sense
Try
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder/file/(.*)/(.*)/ /folder/file.php?x=$1&y=$2 [L]
RewriteRule ^folder/(.*)/ /folder/index.php?x=$1 [L]
The order of the rules is important. You should always put the one with the most rules first as your way was getting to the first rule and then stopping because it was always true due to the (.*) which was capturing the file.
Did you try adding a / before the folder name?
RewriteRule ^folder/(.*)/$ /folder/index.php?x=$1 [L]
RewriteRule ^folder/file/(.*)/(.*)/$ /folder/file.php?x=$1&y=$2 [L]

htaccess multi rss feed redirection with language variable

I have a multilingual blog, default language is Italian and second language is English.
So I have 2 RSS feeds:
/feed
/feed/?lang=en
The first points to Italian the second to English.
I wanna both redirect to Feedburner using .htaccess, the first should point to http://feeds.feedburner.com/SimoBlog and the second to http://feeds.feedburner.com/digitalking/haPl
I successfully done it for the first with this code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/SimoBlog [L,NC,R=302]
</IfModule>
I don't figure out to make it working also for the second feed URL, any help?
Thanks, Simone
You could check if the query string is equal to lang=en:
RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
RewriteCond %{QUERY_STRING} !=lang=en
RewriteRule ^feed/?$ http://feeds.feedburner.com/SimoBlog [L,NC,R=302]
RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
RewriteCond %{QUERY_STRING} =lang=en
RewriteRule ^feed/?$ http://feeds.feedburner.com/digitalking/haPl [L,NC,R=302]

URL rewrite in smarty based website?

I wanted to achieve this
example.com/search_results/?action=search&username[equal]=PorscheSA
to
example.com/PorscheSA
I have used .htaccess for many websites to achieve this, but since this website is smarty based, it doesn't seem to work. Any help will be much appreciated.
Ok, this is the .htaccess file:
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
In order to achieve the following I tried this:
RewriteRule ^([a-zA-Z0-9-_+^/])/$ /search_results/?action=search&username[equal]=$1
and nothing happened.
Your question is still a little vague as to what exactly you expect to have happen, but since you've posted your .htaccess, I'll take a stab at it and see if I get what you were after.
The most obvious reason that your RewriteRule isn't working is that your test pattern doesn't match the URL you've provided as an example, as your RewriteRule requires a trailing slash (and only matches one character before that). Additionally, if you put it after the rules that you currently have in your .htaccess file, it will never match because the request will have already been rewritten to index.php.
I think that you want something like this...
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^.*$ http://example.com/$0 [L,R=301]
# Make sure we end and force the redirect so %{REQUEST_FILENAME} gets changed
RewriteRule ^[a-zA-Z0-9-_+^/]+$ search_results/?action=search&username[equal]=$0 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
However, if the search_results/ directory doesn't exist, then this is just going to be rewritten to index.php anyway, so I'm not sure what the purpose of the redirection would be in that case. And, if it does exist, since your test pattern matches pretty much anything I'd expect to see in a site path, then everything will be rewritten to the search_results/ directory, so very little (if anything) will end up at your site root's index.php.
Based on that, I feel like maybe there's some other criteria that you may have left out, but I could be wrong.

Resources