I need a .htaccess file that follows these rules:
all files (and subfolders/subfiles) of the folders images, css, js, admin, fonts should be reachable
urls like bla.com/info should be redirected to bla.com/index.php?p=info
urls like bla.com/products/22 should be redirected to bla.com/index.php?p=products&cat=22
the url bla.com/products should be redirected to bla.com/index.php?p=products
Can anyone help me with this? This is what I got so far:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /staging/
RewriteRule ^favicon.ico favicon.ico [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?p=$1 [NC,L]
But it only works for the first 2 conditions...
Thanks!!
These 2 rules should work for you:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([a-z0-9-]+)/?$ index.php?p=$1 [NC,QSA,L]
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ index.php?p=$1&cat=$2 [NC,QSA,L]
Try:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /staging/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)(?:/(.*?)/?|)$ index.php?p=$1&cat=$2 [L,QSA]
Related
My .htaccess looks like this..
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [R,L]
</IfModule>
I want to be able to redirect an URL that looks like this..
https://sub.domain.com/ZTHF76
to...
https://www.domain.com/members/invite/ZTHF76
But instead I am getting
https://www.domain.com/members/invite/index.php
I need to keep the first rule to remove index.php from the URI of the rest of the application.
Any help with this greatly appreciated.
You should reorder your rules and keep redirect rule before rewrite one:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I need a URL like this:
http://domain.com/subfolder/file.php?src=quick-brown-fox&m=1&size=320x480
.. changed to:
http://domain.com/subfolder/file/quick-brown-fox/320x480
I updated the htaccess with:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/subfolder/([^\.]+)$ $1.php [NC,L]
but I'm getting a 404. What am I doing wrong?
You could do this in subfolder/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?(.*)$ $1.php [NC,L]
Then capture the URI in php.
You can have this rule in /subfolder/.htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /subfolder/
RewriteRule ^(file)/([^/]+)/([^/]+)/?$ $1.php?src=$2&m=1&size=$3 [QSA,NC,L]
i got a problem with rewriting my edit.php?id=1 to edit/id/1. Right now i have the following in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^edit/id/([^/.]+)$ edit.php?id=$1 [NC]
This doesn't change the url. Can something see what i do wrong?
You need one additional rule to change the URL externally. This should be placed in root .htaccess:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/([^/]+)/edit\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1/edit/id/%2? [R=302,L,NE]
RewriteRule ^([^/]+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L,QSA]
Give this a try and see how it works for you.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
OR you can do this if you only have a couple of directories the same. The will go in the root .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(profiles|customers|test)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
I have created the folder http://domain.com/sport/
What I need it to do now is show contents of http://domain.com/sport/index.php whenever I access http://domain.com/sport/anything/anything/.
Right now its showing contents of http://livesports.pw/index.php
I tried code below, but it's not working.
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)\/$ $1/ [R=301,L]
Note : The folder /sport/ is just an example folder. It can vary. Even if more folder are created, it
must work even for the new ones.
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ /index.php [L]
RewriteRule ^([^/]+)/(.+?)/?$ /$1/index.php [L]
I am posting this question again because I didn't explain clear enough. Here are things that I need to achieve with the .htaccess file:
Re-route /public_html/ to /public_html/myfolder/
Make website/index.php?q=param to website/param/
My php files are inside /public_html/myfolder/ and my image files are inside /public_html/myfolder/images/
Options -Indexes
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
RewriteRule .* https://www.website.com/$1 [L,R=301]
RewriteRule ^$ myfolder/index.php [L]
# Rewrite rules
<IfModule mod_rewrite.c>
#RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ myfolder/index.php?q=$1 [L,QSA]
</IfModule>
The problem is, it redirects fine.. but I can't see any images! It doesn't seem to load my js, css, and etc..
This is the error I get:
1<br />
2<b>Notice</b>: Undefined property: stdClass::$component in <b>/home/website/mypage/includes/Template.class.php</b> on line <b>31</b><br />
I would do something like this. I'm thinking the problem could be the order of the rules, that say, the first rule will try to load the image/js/css since isn't looking if the file exists.
try this:
Options -Indexes
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
RewriteRule .* https://www.website.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ myfolder/index.php?q=$1 [L,QSA]
RewriteRule ^$ myfolder/index.php [L]