I've just created a rule for my .htaccess file to send any traffic going to...
mysite.com/area-scheme.php?scheme_id=XXXto appear as mysite.com/london
The below works fine for those pages, but if I visit mysite.com, its not loading data correctly and I have to actually visit mysite.com/index.php, have I done something wrong?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /area-scheme.php?scheme_id=$1 [L]
can you try this?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /area-scheme.php?scheme_id=$1 [L]
This may avoid rewriting mysite.com that has an empty relative URL.
Related
I want to rewrite this in SEO friendly url.
From - www.example.com/section.php?name=website
To - www.example.com/section/website
I tried this:
RewriteEngine On
RewriteRule ([^/\.]+)/([^/\.]+)?$ section.php?type=$1&service=$2 [NC,L]
I am fetching data using GET method in section.php and pass to the another page but after opening sub folder like www.example.com/{foldername} it returns to the section.php
Thanks. I will appreciate your help.
With your shown samples, please try following htaccess Rules file. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
##Rules for rewrite to section.php as per OP's request.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ section.php?name=$1 [L]
This helps me
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ([^/\.]+)/([^/\.]+)/?$ search.php?type=$1&service=$2
Currently I have the below rules in my htaccess file.
All files should redirect except if they have .htm or .html extensions
RewriteRule \.(htm|html)$ - [NC,L]
RewriteRule ^([A-Za-z0-9-+_./]+)/?$ index.php?page=$1&%{QUERY_STRING}
Now the problem is that tinyMce also has files with .htm, and in that case, the redirect should take place.
So, I want to prevent redirection on .htm files except when the folderstructure/url somewhere contains "tinyMCE" in it...
How can I do this?
Based on your shown samples could you please try following. Trying to fix OP's attempt here, please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !tinyMCE [NC]
RewriteRule ^([A-Za-z0-9-+_./]+)/?$ index.php?page=$1&%{QUERY_STRING} [L]
2nd solution: Or try with following rules too, please try to put ONLY one set of rules either above OR these ones at a time.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!tinyMCE)[A-Za-z0-9-+_./]+)/?$ index.php?page=$1&%{QUERY_STRING} [L]
I am trying to perform a url rewrite where a url like "http://localhost/mywork/product/MTg=/productinfo/" should appear like "http://localhost/mywork/MTg="
Also, the "MTg=" is dynamic and will be varying.
I am not sure as to how to achieve it, can anyone please suggest what RewriteRule i should be writting in my .htaccess
Create mywork/.htaccess file it doesn't exist and have this rule:
RewriteEngine On
RewriteBase /mywork/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1/productinfo/ [L]
I am trying to create pretty URLs using RewriteRule in my .htaccess. However instead of linking the alias with specified pages. My web now only redirects to index.php no matter what address I type in.
Below is my htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /AboutUs.php
Is there anything I need to set up prior to this? or is there something wrong with my htaccess? Please help.
So I'm trying to clean up my URLs ready for my sites public release, this is how current URLs look like:
http://pattersoncode.ca/index.php?a=help
But I'm trying to turn that into
http://pattersoncode.ca/help
I used a mod_rewrite generator online, and it gave me this:
RewriteEngine On
RewriteRule ^([^/]*)$ /?a=$1 [L]
But that gives me an Internal Server Error. Any suggestions?
Your rules are looping, since ^([^/]*)$ will match index.php (or a blank URI). The rewrite engine will keep applying all the rules until the URI stops changing. You can add some conditions to prevent this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /?a=$1 [L]
But are you sure mod_rewrite is loaded? If you put these tags around the rewrite stuff:
<IfModule mod_rewrite.c>
</IfModule>
Are you still getting the 500 server error? If not, then you need to make sure you're loading mod_rewrite in the httpd.conf file, and restart apache.
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?a=$1 [L]
It rewrites any URL except a real file or directory to index.php?a=xyz.