I need the url
from
localhost/project/category?c=electronics
to
localhost/project/category/electronics
I have tried
RewriteRule ^category/([^/\.]+)?$ /category.php?c=$1 [L]
RewriteRule ^category/+?$ /category.php?c=$1 [NC,L]
With your shown samples and attempts please try following htaccess rules. Please do clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /
##External redirect to url change in browser.
RewriteCond %{THE_REQUEST} \s/(project/category)\.php\?c=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to category.php in backend.
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ %{DOCUMENT_ROOT}/$1/$2.php?c=$3 [QSA,L]
RewriteEngine on
RewriteBase /
RewriteRule ^project/category/([0-9a-z]+)$ /project/category?c=$1 [L]
Why is "project/" missing in your original try ?
You have to specify the full path.
You can try this simple rewriteRule wich should works.
Related
I have rewrite:
RewriteRule (.*\.html$) /index.php?$1 [L,QSA]
but some pages have pagination, for example
/test.html?page=2
i need to rewrite it to test-page2.html
i tried
RewriteRule (.*)-page([0-9]*)\.html$ /index.php?$1&page=$2 [NC,L]
but it is not working
With your shown samples, please try following. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##new rule added by me. This will check if a url has html as well as query string then it will rewrite it to html file.
RewriteCond %{THE_REQUEST} \s/([^.]*)\.html\?(page)=(\d+)\s [NC]
RewriteRule ^ %1-%2%3.html [R=301,L]
##OP's previous rule.
##For safer side you could add an additional condition here too.
RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*\.html)$ /index.php?$1 [L,QSA]
Does this work for you?
RewriteEngine on
RewriteCond %{QUERY_STRING} ^([^&]+)&page=([0-9]+)$ [NC]
RewriteRule ^index\.php$ /%1-page%2.html? [L,R]
RewriteRule ^([^-]+)-page([0-9]+)\.html$ /index.php?$1&page=$2 [END]
Make sure to clear your browser cache or use different browser to test this code.
I have this url http://subdomain.domain.com/index.php?page=print-items and I want to remove index.php?page= and only keep what comes after it.
I tried this but it didn't work. it only removes index.php and keeps ?page=print-items
RewriteEngine On
RewriteRule ^([a-z0-9]+) index.php?page=$1
Could you please try following, written and tested as per shown samples.
RewriteEngine ON
RewriteCond %{THE_REQUEST} index\.html\s [NC]
RewriteRule ^(.*/?)/?$ index.html?page=$1 [NC,L]
OR if you are hitting usre friendly URL and you want to redirect in backend into index.html URL with query string then try following.
RewriteEngine ON
RewriteCond %{THE_REQUEST} !index\.html\s [NC]
RewriteRule ^(.*/?)/?$ index.html?page=$1 [NC,L]
Please help me with a redirect issue.
I am trying to redirect from http://www.project/index.php/blog to http://www.project/blog.
I tried the following but it did not work
RewriteRule ^(blog)$ ./index.php/ [L]
Give this a try:
Options +FollowSymlinks
RewriteEngine on
Rewriterule ^index.php/blog(.*)$ http://www.project/blog$1 [r=301,nc]
If you want to append the requested path info at index.php, you might use this RewriteRule
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^ /index.php%{REQUEST_URI} [L]
What I am trying to do:
Change
www.mysitename.com/pages/about
to
www.mysitename.com/about
What I have tried so far:
RewriteEngine on
RewriteRule ^(.*)$ pages/$1
but when I go onto my website and click the about section, the url is still www.**.com/pages/about. htaccess is enabled on my server, so that's not the problem.
What am I doing wrong?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# change URL in browser from /pages/about to /about
RewriteCond %{THE_REQUEST} \s/+pages/(\S*) [NC]
RewriteRule ^ /%1 [R=302,L,NE]
# internally forward /about to /pages/about
RewriteRule ^((?!pages/).+)$ pages/$1 [L,NC]
i am trying to rewrite a URL for SEO purpose.
The old URL is:
http://www.domain.net/index.php?p=beer
The new URL should be:
http://www.domain.net/beer
My Code in the .htaccess is:
RewriteRule ^([^/\.]+)/?$ index.php?p=$1
Even after hours of research, i have no clue why this is not working :(
Here is the complete .htaccess:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} Teoma
RewriteRule ^.* - [F]
rewritecond %{HTTP_HOST} !^www\.domain\.net$ [NC]
rewriterule ^(.*)$ http://www\.domain\.net/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^p=uppic$
RewriteRule ^index\.php$ /? [L,R=301]
RewriteRule ^([^/\.]+)/?$ index.php?p=$1
# Pwd service
AuthType Basic
AuthName "Service"
AuthUserFile /xxxx/www/xxxxxx/xxxxx/xxxxxx/.htpasswd
<Files admin.php>
Require user xxxxxxx
</Files>
Options -Indexes
Thanks in advance!
My final question to this code is:
RewriteRule ^([^/\.]+)/?$ index.php?p=$1
Makes working :
http://www.domain.net/beer
and beer is refering to that page:
http://www.domain.net/index.php?p=beer
Which is great! But if i put a / behind beer, e.g.:
http://www.domain.net/beer/
my beer.php file runs at another path, so no css, images, js and so on is included. Any ideas how to fix that without changing the html to http://www.domain.net/style.css ...?
If you want to capture part of the query string, you must use a RewriteCond with QUERY_STRING
RewriteEngine On
RewriteCond %{QUERY_STRING} p=(.+)
RewriteRule ^/?index.php$ /%1? [R,L]
This redirects the client to the new URL http://www.domain.net/beer.
Have you tried this:?
^([^/\.]+)\/?$
Otherwise I would try the .htacces without the other stuff.
Just:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/\.]+)\/?$ index.php?p=$1