How to set pretty url with .htaccess for different parameters - .htaccess

I'm trying to set pretty URLs for my website. Thanks to #JonLin I managed to change site with two parameters. The other thing I want to do is make it work for one parameter as well. Here is the code
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+devplus0/index\.php\?key=([^&]+)&lang=([^&\ ]+)
RewriteRUle ^ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?key=$2&lang=$1 [L,QSA]
You can check the site prettyurl from http://www.devplus.co/english/about-us

For one param, add:
RewriteCond %{THE_REQUEST} \ /+devplus0/index\.php\?key=([^&\ ]+)
RewriteRUle ^ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ index.php?key=$1 [L,QSA]

Related

Rewrite matching URL

I'm trying to rewrite matching URLs of my website but it's not working for some reason, don't know why...
Here is current URL:
example.com/details.php?p=10&text=some-text-is-here
want to write like this
example.com/post-details/10/some-text-is-here
My .htaccess is here
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/details\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /details/%1? [R=301,L]
RewriteRule ^details/([0-9]+)$ /details.php?id=$1 [L]
any help would be appreciated
Try this :
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/details\.php\?p=(\d+)&text=(.+)\s [NC]
RewriteRule ^ /post-details/%1/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteRule ^post-details/(\d+)/(.+)$ /details.php?p=$1&text=$2 [L,NE]
Note: clear browser cache the test

How can I Remove Question Mark and Change Name From URL?

i'm trying to remove ? from the URL currently url is showing as
http://www.tenantfind.co.uk/blog-detail.php?id=4
and it should open as
http://www.tenantfind.co.uk/blog/new-legal-helpline
i tried the following solution
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(blog-detail)?\?([^&\ ]+)
RewriteRule ^ /%1? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog-detail?$1 [L]
but it is redirecting to following link and showing blank page, no data on page
http://www.tenantfind.co.uk/blog-detail
Try with:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(?:blog-detail)?\?([^&\ ]+)
RewriteRule ^ /blog/%1? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/?$ /blog-detail?$1 [L]

Simple .htaccess rewrite for single get parameter

How can I rewrite
http://data.example.com/?file=test
to
http://data.example.com/test
via .htaccess?
Try:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /\?file=([^\ &]+)
RewriteRule ^ /%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?file=$1 [L,QSA]

redirect m.php to m.domain.com htaccess

Is it possible to redirect
http://www.url.com/m.php?name=Bill
to
http://m.url.com/Bill/
via htaccess?
I have seen some examples but I'm not sure what
they use to accomplish that
How about:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?url\.com$ [NC]
RewriteCond %{THE_REQUEST} \ /+m\.php\?name=([^&\ ]+)
RewriteRule ^ http://m.url.com/%1/? [L,R]
RewriteCond %{HTTP_HOST} ^m\.url\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /m.php?name=$1 [L,QSA]
assuming that both m.url.com and www.url.com point to the same document root.

SEF urls htaccess

Currently my url structure is like:
http://mysite/index.php?page=main
http://mysite/index.php?page=bowling
http://mysite/index.php?page=inn
How to optimize this structure by leaving just (main,bowling,inn respectively) ?
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+index\.php\?page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{THE_REQUEST} \ /+index\.php\?page=([^&\ ]+)
RewriteRule ^ /%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L]
make sure mod_rewrite is turned on.

Resources