I'm running Windows 7 xampp server it has Apache and it has lines that are needed to uncomment to work fine.
However when I try to use RewriteRule I bump into the problem.
When I write wrong code at the start of htaccess it throws error 500, there are few commands that works, but when I use RewriteRule it simply ignore that part , unless if I write something syntax wise wrong then it reacts as error, but i have never seen my link changed.
.htaccess file is placed at myDomain directory
Can it possibly be issue of software or it's my code?
I have this dynamic link:
http://localhost//myDomain/folder/ad.php?title=theTitle&id=1
and I need to get this:
http://localhost//myDomain/folder/theTitle/1
My htaccess file looks like this:
RewriteEngine on
RewriteBase /myDomain/folder
RewriteCond %{REQUEST_URI} ^/ad.php$ [NC]
RewriteCond %{QUERY_STRING} ^title=(.*)&id=(.*)$
RewriteRule (.*) http://localhost/myDomain/folder/%1/%2.aspx? [R=301,L]
Any help would be highly honored :)
You can have these rules in /myDomain/folder/.htaccess:
RewriteEngine on
RewriteBase /myDomain/folder/
RewriteCond %{THE_REQUEST} /ad\.php\?title=([^\s&]+)&id=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=302,L]
RewriteRule ^([^/.]+)/([0-9]+)/?$ ad.php?title=$1&id=$2 [L,QSA]
Related
I've been crawling forums for about 2 hours and still haven't found the solution to my problem so I am turning to you guys for help.
My URL looks like this
http://sevalinmutfagi.com/list.php?id=1?kategori=borekler
I want it to look like this
http://sevalinmutfagi.com/tarifler/borekler
I try so much rewrite example but my index file at a subfolder in /View/ so I can't rewrite my URLs
here my .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?sevalinmutfagi.com$ [NC]
RewriteCond %{REQUEST_URI} !^/View/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /View/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?sevalinmutfagi.com$ [NC]
RewriteRule ^(/)?$ View/index.php [L]
This code works well for redirect subfolder all pages but I try to add rewrite URL codes can't work. I hope that has been revealing. Thanks to every for help.
that's worked for me fine.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ /subfolder/$1 [NC,L]
The FIRST thing to learn about mod_rewrite is when NOT to use it. Since mod_alias handles your specific task very nicely, that’s what I’d use:
Redirect 301 / /subfolder/
Since that looks like it would be “loopy,” you could fall back on mod_rewrite:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^subfolder/
RewriteRule .? subfolder%{REQUEST_URI} [R=301,L]
There’s just too much wrong with your attempt to cover … and I’ve addressed exactly those issues many times in many threads. Therefore, you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too
I've been testing this in WAMP and I can't get it to work. I believe WAMP is set up properly due to the error message I'm receiving and it works no problem when I don't use the .htaccess file.
I have a filename that I'm using for testing called Feedback.php. Instead of displaying as www.mysite.com/Feedback.php. I'm trying to get it to just be www.mysite.com/Feedback.
.htaccess file
RewriteEngine on
RewriteRule ^Feedback.php/?$ Feedback [NC]
The error message that I receive is
"Not FoundThe requested URL /Feedback was not found on this server."
Are there two files required for reWriteRule to work?
I'm also trying to get this to work for my index.php to just be www.mysite.com which may be a different monster.
What should my navbar links be? Right now they are Feedback Should href perhaps be href="Feedback" once I get this working?
EDIT: I had the ReWriteRule variables backwards. Instead of
RewriteRule ^Feedback.php/?$ Feedback [NC]
I should have
RewriteRule ^Feedback/$ /Feedback.php [NC,L]
The rewrite doesn't look to have taken place though as it still reads localhost/Feedback.php
You may use this to remove .php extension from your pages as well as omitting the index part to your website:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{THE_REQUEST} /index
RewriteRule ^index$ http://yourwebsite.com/ [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
i have already search for a long time and i could not figure our why Rewrite Rule is not working. i want to translate this url
http://localhost/uniwood/template-allgemein.html?postname=kontakt&pageid=27
to
http://localhost/postname/kontakt.html
here the code in the htaccess file
RewriteEngine On
RewriteRule ^postname/([^/]*)\.html$ /uniwood/template-allgemein.html?postname=$1&pageid=27 [L]
I'am using locally on my machine the mamp pro webserver and checked that AllowOverride is on "all".
I do not get any mistakes! Also no error logs!
thanks!
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /template-allgemein\.html\?postname=([^\s&]+)&pageid=27 [NC]
RewriteRule ^ /postname/%1.html? [R=302,L,NE]
RewriteRule ^postname/[^.]+)\.html$ /template-allgemein.html?postname=$1&pageid=27 [L,NC,QSA]
I'll be honest in saying I have very little experience with .htaccess as I've always wanted to stay away from it as best I can. However, I've recently wanted to tidy up my urls and I've found that it's possible through .htaccess and rewriting.
Basically, I want to rewrite a url like:
www.mysite.com/profile.php?id=48194
To something like:
www.mysite.com/profile/48194
Here's the code I have currently:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^profile/(.*)/$ profile.php?id=$1
The line I'm trying to use is on the very bottom, RewriteRule ^profile/(.*)/$ profile.php?id=$1. The rest is used to remove the page extensions from the urls. I've changed $1 to $2 thinking perhaps it was conflicting with the code above, but nothing changed.
I also removed all the code except for RewriteEngine on and the last line thinking maybe the codes were conflicting but, again, nothing changed or worked. The rest of the code does work, removing the extensions from urls that is, so I know the rewrite thing is on.
Could someone try to break down and explain what I did wrong and how all this works? As well as providing a working example of the thing I'm trying to accomplish?
Thanks in advance!
Change order of your rules and use MultiViews option. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
RewriteEngine on
RewriteBase /
RewriteRule ^profile/([^/]+)/?$ profile.php?id=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
I don't know what changed in the past--this used to work:
Accessing a URL on my server like the following, doesn't work: http://www.domain.com/folder/file.php?variable=a&variable2=b
I'm getting a "Not found The requested address 406.shtml was not found on this server." message.
However, if I access this, it works:
http://www.domain.com/folder/file.php
Adding the question mark after file.php is what makes it break. I have never experienced a problem like this before. At first I thought that .htaccess had something to do with it, but I know as a fact that it hasn't been edited at all in the past.
Any ideas? I'm using CakePHP, but I doubt that has anything to do with it; this has worked before. All suggestions are welcome!
EDIT:
The /app/webroot .htaccess file has this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
As far as I know, this hasn't changed at all, and the URL worked with this. The .htaccess file right under /public_html/ contains this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
You've got an error in your apache config. It's attempting to give you the 406 error page, but can't find it. If you fix that you may get a more informative error.
This link may help you with the root of the problem: http://urbangiraffe.com/2005/08/20/mysterious-406-error/
It could also be caused by mod_security. If it's not your server you should ask your hosting provider.
99.9% probability that this is being caused by a change in your htaccess file. Something is checking for a query string and redirecting to or trying to load a file that doesn't exist.