I have the following rules setup for my blog and they seem to work just fine.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(index\.php|(modules|css|files|fonts|ico|img|js)/)
RewriteRule ^([^/]*)/page/([^/]*)$ /framework/?p=$1&page=$2 [L]
RewriteRule ^([^/]*)/search/([^/]*)$ /framework/?p=$1&search=$2 [L]
RewriteRule ^([^/]*)/search/([^/]*)/page/([^/]*)$ /framework/?p=$1&search=$2&page=$3 [L]
So I was feeling confident and wanted to add one more rule for the just the basic page.
so I added this rule
RewriteRule ^([^/]*)$ /framework/?p=$1 [L]
so that my htaccess file now looks like this
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(index\.php|(modules|css|files|fonts|ico|img|js)/)
RewriteRule ^([^/]*)$ /framework/?p=$1 [L]
RewriteRule ^([^/]*)/page/([^/]*)$ /framework/?p=$1&page=$2 [L]
RewriteRule ^([^/]*)/search/([^/]*)$ /framework/?p=$1&search=$2 [L]
RewriteRule ^([^/]*)/search/([^/]*)/page/([^/]*)$ /framework/?p=$1&search=$2&page=$3 [L]
but for if I go to http://www.example.com/framework/blog I get a 500 Internal Server Error if I take out the line and go to http://www.example.com/framework/blog/page/2 it loads my second page without any issues.
I am not sure what I am doing wrong? Any advice would be appreciated.
You can use:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /framework/
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/page/([^/]*)$ ?p=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/search/([^/]*)/page/([^/]*)$ ?p=$1&search=$2&page=$3 [L,QSA]
RewriteRule ^([^/]+)/search/([^/]*)$ ?p=$1&search=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ ?p=$1 [L,QSA]
Related
I have been trying to apply a rewrite rule to change my urls which currently look like this:
www.mysite.com/my-site/en
change to:
www.my-site.com/en or /es
but I want it to be forceful and not allow someone to deliberately type in the latter.
Also
www.my-site.com/en/?page=car&category=15
change to
www.my-site.com/en/car/15 (or I can just put the category name instead)
I also have this:
www.my-site.com/en/?page=catalogue-item&category=204&id=563
which I want to change to:
www.my-site.com/en/563 (or I can just put in the item name instead)
Here is my htaccess so far:
# RewriteOptions inherit
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^my-site.com [NC]
RewriteRule ^(.*)$ http://www.my-site.com/$1 [L,R=301,NC]
RewriteRule ^$ my-site/ [L,NS,R=301]
RewriteCond %{HTTP_HOST} ^www.my-site.com/my\-site/ [NC]
RewriteRule ^(.*)$ http://www.my-site.com/$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ my-site/$1 [L,NS]
RewriteRule ^([^/]*)$ /en/?page=$1 [L]
RewriteRule ^([^/]*)$ /es/?page=$1 [L]
RewriteRule ^([^/]*)/([^/]*)$ /en/?page=$1&category=$2 [L]
RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ my-site/$1 [L,NS]
</IfModule>
I thank you in advance and hope someone could point out my problem, thank you again.
I am trying to rewrite my page like abc.com/profile.php?id=abc to abc.com/abc
Can you guide me?
When I try to add the following line, i getting 500 page error
RewriteRule ^([^/]*)$ /profile.php?id=$1 [L]
my htaccess
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /detail.php?type=$1&title=$2&id=$3 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?pn=$1&type=$2 [L]
RewriteRule ^contact-us.html$ contact-us.php [NC,L]
RewriteRule ^about-us.html$ /about-us.php [NC,L]
RewriteRule ^privacy-policy.html$ /privacy-policy.php [NC,L]
RewriteRule ^legal.html$ /legal.php [NC,L]
RewriteRule ^search$ /search.php [NC,L]
RewriteRule ^disclaimer.html$ /disclaimer.php [NC,L]
RewriteRule ^submit-job$ /submit-job.php [NC,L]
I have a htaccess file to match all of the occurrences. but it stops at second one. when i load /galeri/kategori/galeri-kategory-albumname/ it loads sayfa.php which has no relation with gallery page itself. It works fine on my localhost but trying to figure out why its not working in server.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)$ index.php?p=$1 [L]
RewriteRule ^(.*?)\/sayfa(.*?)$ index.php?p=$1&sayfa=$2 [L]
RewriteRule ^(.*?)\/kategori\/(.*?)\/$ index.php?p=$1&kategori=$2 [L]
RewriteRule ^(.*?)\/kategori\/(.*?)\/(.*?)\/$ index.php?p=$1&kategori=$2&sayfa=$3 [L}
Have it this way:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(.*)/kategori/(.*)/(.*)/?$ index.php?p=$1&kategori=$2&sayfa=$3 [L,QSA]
RewriteRule ^(.*)/kategori/(.*?)/?$ index.php?p=$1&kategori=$2 [L,QSA]
RewriteRule ^(.*)/sayfa(.*?)/?$ index.php?p=$1&sayfa=$2 [L,QSA]
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
I'm using this htaccess code. I expect any call to be directed to https://www.mysite.com/theme/topic. I've really looked lots of links & helps - the result is only and ever:
https://www.example.com/index.php
so the /theme/topic are not in the output url, only the index.php
what is wrong here? thanks for any help
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### If file exists, use it.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php [L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,QSA,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,QSA,R=301]
</IfModule>
you say it yourself:
so the /theme/topic are not in the output url, only the index.php
try to change the line
RewriteRule ^(.*)$ index.php [L]
into
RewriteRule ^(.*)$ /theme/topic/$1 [L]
Or is there a specific reason why not to put it there?
[edit after clarification]
So you have 2 dynamic parameters and want to rewrite yourdomain.com/parameter1/parameter2 to yourdomain.com/index.php?p1=parameter1&p2=parameter2? Then try the following:
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?p1=$1&p2=$2 [L]
[re-edit after more clarification]
Oh, so it is just redirecting from http to https and redirecting to www? Then you can just do the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC, OR]
RewriteCond %{HTTPS} !on
RewriteRule ^.*$ https://www.mysite.com/%{REQUEST_URI} [R=301,L]
</IfModule>
I would like to have a RewriteRule match the "base" url/path of my site.
My base URL, once in prod, will be something like http://www.site.com, but is currently http://localhost/dev/site/ in dev. .htaccess file is in the "site" folder.
In the following examples, the first RewriteRule is the problem, and I can't get it to work. The 2nd and 3rd RewriteRules work fine. I need it to bring to index.php?l=default&rte=index if I reach the base path/URL.
Thanks.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/$ index.php?l=default&rte=index [NC,L]
RewriteRule ^([a-zA-Z]{2})/$ index.php?l=$1&rte=index [NC,L]
RewriteRule ^([a-zA-Z]{2})/([a-zA-Z-]+)$ index.php?l=$1&rte=$2 [NC,L,QSA]
Try these rules:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^/?$ index.php?l=default&rte=index [QSA,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([a-zA-Z]{2})/?$ index.php?l=$1&rte=index [QSA,L]
RewriteRule ^([a-zA-Z]{2})/([a-zA-Z-]+)/?$ index.php?l=$1&rte=$2 [QSA,L,QSA]