I have to write a htaccess to rewrite the links as follows and also a redirection of 404
error pages to my sites root (home page)
www.example.com/index.php?page=find&name=detail&id=109&cid=8
www.example.com/index.php?page=find&name=detail&id=109
www.example.com/index.php?page=find&name=detail
www.example.com/index.php?page=find
should be rewritten to
www.example.com/find/name/detail/id/109/cid/8
www.example.com/find/name/detail/id/109
www.example.com/find/name/detail
www.example.com/find
Your htaccess rules,
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?file=$1 [L,QSA]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/id/([0-9]+)/cid/([0-9]+)/$ index.php?page=find&name=detail&id=109&cid=8 [L]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/id/([0-9]+)/$ index.php?page=find&name=detail&id=109 [L]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/$ index.php?page=find&name=detail [L]
RewriteRule ^([a-zA-Z]+)/$ index.php?page=find [L]
</IfModule>
Try:
RewriteEngine On
RewriteRule ^find$ index.php?page=find [L,QSA]
RewriteRule ^(find)/([^/]+)/([^/]+)(.*)$ /$1$4?$2=$3 [L,QSA]
FallbackResource /
Try this code:
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5&$6=$7$8=$9 [L]
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5&$6=$7 [L]
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5 [L]
RewriteRule (.*)/([a-zA-Z]*)/(.*)\.html index.php?itfpage=$1&$2=$3 [L]
Related
I tried usingĀ
ErrorDocument 404 /abc/404.php
But when the wrong URL is entered it redirects to the main page, not to the 404 error page
I have a htaccess file with this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} /search(?:\.php)?\?search=([^\s&]+) [NC]
RewriteRule ^ search/%1? [R=302,L,NE]
RewriteRule ^search/(.*)/page/(.*)/?$ search.php?search=$1&page=$2 [NC,L]
RewriteRule ^search/(.*)$ search.php?search=$1 [L,QSA,NC]
RewriteRule ^category/(.*)/page/(.*)/?$ category.php?id=$1&page=$2 [NC,L]
RewriteRule ^category/(.*)$ category.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
ErrorDocument 404 /abc/404.php
These two rules...
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [L]
Replace any URL that is accessed with the replacement... Unless the accessed URL is a real file/directory. As per the RewriteCond rules preceding them:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
If you don't want to divert every request that isn't a real file/directory then you need to change those rules...
I want to set a priority in my .htaccess.
Ok, I've got folders on my root project, schema:
-root:
-core
-includes
-pages:
- profile.php
-etc
-support
-infractions
-.htaccess
and what I want to do is:
If the URL is like https://example.com/support, show the /support/index.php.
I've tried -Indexes option but it doesn't works or doesn't meet my needs.
My .htaccess is like:
Options +FollowSymlinks
Options +Indexes
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^fenixcms\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://fenixcms.com/$1 [R,L]
RewriteBase /
DirectoryIndex pages/index.php
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^alert/([^/\.]+)/?$ pages/alert.php?id=$1 [L]
RewriteRule ^player/([^/\.]+)/?$ pages/profile.php?name=$1 [L]
RewriteRule ^forums/new_topic/([^/\.]+)/?$ /forums/new_topic.php?c=$1 [L]
RewriteRule ^forums/topics/([^/\.]+)/posts/edit/([^/\.]+)/?$ /forums/edit_post.php?tid=$1&pid=$2 [L]
RewriteRule ^forums/topics/([^/\.]+)/posts/new/?$ /forums/new_post.php?tid=$1 [L]
RewriteRule ^forums/topics/([^/\.]+)/posts/reply_to_id/([^/\.]+)/?$ /forums/new_quote.php?tid=$1&pid=$2 [L]
RewriteRule ^forums/topics/([^/\.]+)/edit/?$ /forums/edit_topic.php?tid=$1 [L]
RewriteRule ^forums/topics/([^/\.]+)/?$ /forums/topic.php?id=$1 [L]
RewriteRule ^forums/topics/([^/\.]+)/posts/delete/([^/\.]+)/?$ /forums/delete_post.php?tid=$1&pid=$2 [L]
RewriteRule ^forums/categories/([^/\.]+)/?$ /forums/categories.php?s=$1 [L]
RewriteRule ^forums/posts/([^/\.]+)/?$ /forums/posts.php?pid=$1 [L]
RewriteRule ^forums/([^/\.]+)/?$ /forums/$1.php [L]
RewriteRule ^revisions/([^/\.]+)/?$ pages/revisions.php?action=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)/([^/\.]+)/?$ /$1/$2.php [L]
RewriteRule ^([^\.]+)/?$ /$1/index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ pages/$1.php [NC,L]
I have the following lines in my .htaccess
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ seo.php?p=$1 [L]
RewriteRule ^seo/site:(.*)$ seo.php?p=seo&domain=/$1&status=seo [QSA]
RewriteRule ^seo/(.*)$ seo.php?p=seo&domain=/$1&status=seo [L]
RewriteRule ^admin/page:(.*)$ seo.php?p=admin&page=/$1 [L]
RewriteRule ^webagent/page:(.*)$ seo.php?p=webagent&page=/$1 [L]
RewriteRule ^setlang:(.*)$ seo.php?setlang=/$1 [L]
RewriteRule ^(.*)/setlang:(.*)$ seo.php?p=/$1&setlang=/$2 [L]
</IfModule>
The problem is that only first Rule works normal. it takes pages from currently defined folder in php
When i try to open
seo/domain.com
it doesn't work but when i open
seo.php?p=seo&domain=domain.com&status=seo
works very well.
Where i go wrong with this .htaccess file.
Have your rules like this:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^seo/site:(.*)$ seo.php?p=seo&domain=/$1&status=seo [L,QSA]
RewriteRule ^seo/(.*)$ seo.php?p=seo&domain=/$1&status=seo [L,QSA]
RewriteRule ^admin/page:(.*)$ seo.php?p=admin&page=/$1 [L,QSA]
RewriteRule ^webagent/page:(.*)$ seo.php?p=webagent&page=/$1 [L,QSA]
RewriteRule ^setlang:(.*)$ seo.php?setlang=/$1 [L,QSA]
RewriteRule ^(.*)/setlang:(.*)$ seo.php?p=/$1&setlang=/$2 [L,QSA]
RewriteRule ^(.*)$ seo.php?p=$1 [L,QSA]
</IfModule>
I've got old urls and want to remove the /index.php/ via .htaccess:
So old url is:
www.mysite.com/index.php/onesite.html
rewrite in .htaccess into
www.mysite.com/onesite.html
How can I do that?
Thx for your help
Adding the following code to your htaccess will allow this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index.php/(.*)$ www.mysite.com/$1 [R=302,L]
Changing 302 to 301 when you are sure the redirect is working
Try this one:
RewriteRule ^index.php/(.*?)$ http://%{HTTP_HOST}/$1 [R=301,L]
Just add this in your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
If you site is in subfolder then
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
</IfModule>
You can use these 2 rules in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^index\.php(/.*)?$ $1 [L,R=301,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ /index.php/$1 [L]
I am trying to point www.olddomain.com/whatever to www.newdomain.com/whatever (as well as without the www.), but the Wordpress permalinks are not staying intact. Please help!!
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^olddomain.com [nc]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [nc]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc]
</IfModule>
I fixed it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^olddomain.com [nc]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc,L]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [nc]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
A much simpler solution. Change the .htaccess to just say:
RedirectMatch 301 /(.*) http://www.newdomain.com/$1
You will need to move this block:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
behind the redirects. It grabs everything and sends it to index.php.