I have following rewriterules:
RewriteEngine On
RewriteRule ^([^\-]*)-(.*)-von-(.*)\.html$ $1index.php?filter=$2&marke=$3 [QSA]
RewriteRule ^([^\-]*)-von-(.*)\.html$ $1index.php?marke=$2 [QSA]
RewriteRule ^([^\-]*)-(.*)\.html$ $1index.php?filter=$2 [QSA]
RewriteRule ^(.*)\.html$ $1index.php
The first 3 rules are working, but the fourth, just rewrite index.php to .html is not. What is wrong here?
EDIT:
The URL is example.com/folder/subfolder/index.php
In the folder I got following htaccess:
RewriteEngine on
RewriteRule ^subfolder(.*) subfolder/$1
And the htaccess in subfolder is the one above
Now the URL for the first rule is example.com/folder/subfolder-value1-von-value2.html and works, for the second and third rule it's example.com/folder/subfolder-value1.html and example.com/folder/subfolder-von-value2.html
So with logic the fourth rule should also work just without the parameters but it's not working
Place this in /folder/.htaccess:
RewriteEngine on
RewriteRule ^subfolder\.html$ subfolder/index.php [L,NC]
RewriteRule ^subfolder(.+) subfolder/$1 [L,NC]
You shouldn't add $1 to the second part of the rule.it'll append the first matching group to the index.php file name. what you are currently getting is 'indexindex.php'
if you just want to rewrite index.html to index.php then you can place following line at the end of the file.
RewriteRule ^index.html$ index.php [L,NC]
also you might wanna remove $1 part from other lines as well.
Can you try this & see ?
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php
Related
I want to create pretty url. But, I got some problem with .htaccess. For example I have url domain/some.php?f=query-string.
I want to change domain/query-string (expected url). Is that possible to change / redirect via .htaccess. Or maybe from php file itsself.
this is a bit of htaccess snippet i made, but i get it blank/error page
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]
</IfModule>
Thanks for your attention.
RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]
In .htaccess, the URL-path matched by the RewriteRule pattern does not start with a slash, so the above will never match and it will do nothing. This should be written like the following instead:
RewriteRule ^([^/.]+)$ some.php?f=$1 [L]
The NC flag is not required here, since the regex is already "case-insensitive".
I have the following .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^/(.*)/(.*)/(.*)$ index.php?pageLevel1=$1&pageLevel2=$2&pageLevel3=$3 [L,R=301]
When I access my website using http://www.domain.com/testpage/ it gives me the 404 Not Found error. What am I doing wrong?
PS: currently the index.php files just echo the pageLevel1, pageLevel2 and pageLevel3 values.
Remove the leading slash from Rewrite pattern
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/(.*)/(.*)$ index.php?pageLevel1=$1&pageLevel2=$2&pageLevel3=$3 [L,R=301]
First of, I don't know why are you using the 301 redirection at all? If you want to accept all characters in the url you just need to have a catch-all rewrite rule like this:
RewriteRule ^(.*)$ index.php?param=$1 [L]
If you want to catch the parameters like you defined, the rewrite rules can be like this:
RewriteRule ^([A-Za-z-]+)/([A-Za-z-]+)/([A-Za-z-]+)$ index.php?pageLevel1=$1&pageLevel2=$2&pageLevel3=$3 [L]
UPDATE:
The completed rules in your case (three page levels), with URL slugs which accepts letters and numbers can be like:
RewriteRule ^([A-Za-z0-9-]+)$ index.php?pageLevel1=$1&pageLevel2=$2 [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php?pageLevel1=$1&pageLevel2=$2 [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php?pageLevel1=$1&pageLevel2=$2&pageLevel3=$3 [L]
This way you can access pages like:
www.domain.com/test
www.domain.com/test/another-test
www.domain.com/test/another-test/new-level
I am trying to rewrite the url like
http://test.com/1234
to
http://test.com/index.php?a=1234
and my .htaccess file
RewriteEngine On
RewriteRule /^[a-zA-Z0-9]/?$ index.php?key=$1 [NC,L]
but nothing is happening it simply shows object not found error, .htaccess file is already in the root directory so help needed
P.S. I am a beginner in rewriting.
Try this rewrite rule:
RewriteEngine On
Options +FollowSymlinks
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?key=$1 [NC,L]
You need the brackets to group characters and re-use them as the $1 parameter.
You don't need the /
If you have a pattern like [0-9] you need a * or + if you want to match more than one character.
Btw, if the key parameter only accepts numbers, use:
RewriteEngine On
Options +FollowSymlinks
RewriteRule ^([0-9]+)/?$ index.php?key=$1 [NC,L]
try this
RewriteRule ^(.*)$ index.php?a=$1 [L,QSA]
^(.*)$ results in passing down the whole request path as one parameter
QSA results in appending any query string to the request
?a=$1 specify how the parameter is passed down
Try this rewrite rule:
RewriteRule ^(.*)$ index.php?a=$1 [QSA,L]
Basically I want to rewrite my urls so that it is website.com/folder/ sometimes though I need it to rewrite also website.com/folder/page/
Currently I have it working with just the website.com/folder/ but can not get it to check if there is a page, if I create just another rule under the folder one it reads that one, and gives me an empty page var, which is breaking my php. I struggle with .htaccess and any help would be appreciated.
Here is what I have that works with just the folder but I can not include a page.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/?(css|js|images|html|docs)/
RewriteRule ^([^/]*)/$ /?folder=$1 [QSA]
Here is what I tried to get it to work with either just a folder, or a folder and page
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/?(css|js|images|html|doc)/
RewriteRule ^([^/]*)/$ /?folder=$1 [QSA]
RewriteCond %{REQUEST_URI} !^/?(css|js|images|html|doc)/
RewriteRule ^([^/]*)/([^/]*)/$ /?folder=$1&page=$2 [L,QSA]
Please Help!
Accordingly to the RewriteRule docs you should reverse the rules order in your rules set. Because in your configuration both rules have the same RewriteCond, the most specific rule (folder + page) should be atop and the most general rule should be the last one. If not when the first rule is matched the URL is rewritten and the second rule never matches. Also, probably you want to remove the trailing forward slash in the pattern of your folder + page rule (assuming that the second group in the pattern matches a page not a folder). So I think the whole thing should read:
RewriteCond %{REQUEST_URI} !^/?(css|js|images|html|doc)/
RewriteRule ^([^/]*)/([^/]*)$ /?folder=$1&page=$2 [L,QSA]
RewriteCond %{REQUEST_URI} !^/?(css|js|images|html|doc)/
RewriteRule ^([^/]*)/$ /?folder=$1 [L, QSA]
For my site I have a RewriteRule that points the URL http://www.mysite.com/work to a work.php file. I also have a directory called "work" that has files in it, like project1.php, project2.php, etc...
What rules would I have to write so that the URL http://www.mysite.com/work knows to go to the work.php file, but the URL http://www.mysite.com/work/project1 knows I mean to go inside the directory "work" and display the project1.php file?
EDIT: Should point out, this is what I'm currently working with:
RewriteEngine On
RewriteBase /beta/
RewriteRule ^([a-z]+)$ $1.php [L]
Any additional tips to improve this security-wise? (Stopping directory jumping, etc...)
Try this:
RewriteEngin On
RewriteBase /
RewriteRule ^work$ /work.php [QSA,L]
That will ensure that http://www.mysite.com/work (no trailing slash) will go to your work.php file.
If you also want http://www.mysite.com/work/ (with trailing slash) to go work.php, add this line just above the last RewriteRule.
RewriteRule ^work/$ /work [R=301,QSA,L]
That will redirect it to the URL with no trailing slash thus, displaying the work.php file.
UPDATE: Since you already have a RewriteBase directive, just put the RewriteRule line(s) right after your RewriteBase but before your RewriteRule as the rule you're using a catch-all and will match everything.
This is the answer to your question. It works for me.
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z]+)$ $1.php [L]
Simply remove beta/
Try this rule:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* $0.php [L]