I am currently trying to figure out how to create an htaccess file that will allow me to perform the following, however I have searched everywhere, and on stackoverflow but I cannot find a solution.
I have an existing site, with a directory /brands/, and an htaccess file setup so that putting anything after brands e.g. /brands/diesel redirects to /brands/index.php?brand=diesel. What I now need to do is redirect anything further in the URL to a seperate page ( in the same directory ), for example /brands/diesel/jeans/male will redirect to inner.php?sear=diesel&t=jeans&g=male
I have tried the following with no success:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ inner.php?sear=$1&t=$2&g=$3 [L]
Anyone who is competent at writing htaccess files will probably be able to spot what is wrong immediately, but unfortunately I am not great with these.
Any help would be greatly appreciated.
I think you might have to setup RewriteBase.
RewriteBase /brands/
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ inner.php?sear=$1&t=$2&g=$3 [L]
Try these rules
RewriteEngine On
RewriteBase /brands/
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/?$ inner.php?sear=$1&t=$2&g=$3 [L,QSA]
RewriteRule ^([^/.]+)/([^/]+)/?$ inner.php?sear=$1&t=$2 [L,QSA]
RewriteRule ^([^/.]+)/?$ inner.php?sear=$1 [L,QSA]
Related
I've been working on a module for a PHP-based application that would allow users to create custom pages. These pages have a URL structure as follows:
yourdomain.com/page.php?url=random-slug
I would like to have these URLs rewritten to use a more SEO-friendly approach:
yourdomain.com/random-slug/
In addition, there should two (2) redirects that accompany this rewrite:
yourdomain.com/page.php?url=random-slug => yourdomain.com/random-slug/
yourdomain.com/random-slug => yourdomain.com/random-slug/
Would this be possible? If so, what would the .htaccess (Apache) file look like to accomplish this? I have tried the following for the rewrite:
RewriteRule ^([^/]*)?.php$ ./page.php?url=$1 [L,NC]
Unfortunately, the above also seems to break other links on the site as well. I'm not exactly sure why yet but was hoping someone could point me in the right direction.
Thank you for your help!
Edit:
I was able to find a way to accomplish this with the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*?)/?$ ./page.php?url=$1 [L]
RewriteCond %{THE_REQUEST} /page\.php\?url=([^\&\ ]+)
RewriteRule ^/?page\.php$ ./%1/? [R=301, L]
Hopefully this will help anyone else with a similar request :)
I've been searching and cannot find an answer that suits my needs. It is a rather simple question I assume.
The point is that I need to rewrite my files to a name of my liking. For example I have, 'www.mydomain.com/account_index.php' which I want to rewrite to www.mydomain.com/account
Thus far I had this, but that doesn't seem to work with multiple lines.
Rewriteengine on
rewriterule ^support account_ticket.php [L]
rewriterule ^account account_index.php [L]
So in short, I want my website to redirect /account to account_index.php and the other way around.
Thanks in advance!
I found the answer for those that are wondering.
I had to put a RewriteCond before every RewriteRule.
So if I wanted to go to www.mydomain.com/account. I'd have this:
RewriteCond %{REQUEST_URI} ^/account$ [NC]
RewriteRule ^account account_index.php [NC,L]
This means that /account is now linked to account_index.php.
Have a nice day!
Hey so I've searched up and down through the questions without finding the answer to what I'm looking for. If this is a dupe I apologize, please direct me to the answer.
So I've set up my htaccess so that if someone types in:
www.example.com/menu
it loads the follow page "www.example.com/page.php".
The problem I'm facing is that if someone types in:
www.example.com/page.php
directly, it doesn't change the URL to "www.example.com/menu" and just remains showing as "www.example.com/page.php"
How can I make it so that if person types in either "www.example.com/page.php" or "www.example.com/menu" it will always show the url as "www.example.com/menu"?
here's my htaccess:
RewriteEngine On
RewriteRule ^menu/?$ page.php [NC,L]
Put this code in your htaccess (in root folder)
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/page\.php [NC]
RewriteRule . /menu [R=301,L]
RewriteRule ^menu$ /page.php [L]
This is my .htaccess code.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ movie.php?name=$1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.in$
RewriteRule ^/?$ "http\:\/\/example\.in" [R=301,L]
ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None
I need a clean URL for my website.
I've consulted lots of tutorials and forums and created the above code.
But it's not working. Almost I'm fighting with code.
I don't understand the clean URL concept clearly. Are there any codings I have to write in my PHP file?
<a href='movie.php?name=titanic'> Titanic </a>
I have this link in my index.php file.
I'd like example.in/movie/titanic when I click on the link "Titanic".
Also I'd like to get the value by $_[request].
What exactly do I have to do? Please don't mark this question as duplicate, I've searched a lot and haven't got the concept clearly. Please help me out.
Thanks.
The rules in .htaccess work on url's relative to the directory your .htaccess file is in. If you have a .htaccess in your www-root, then the first argument of RewriteRule will match everything behind the domain name and before the query string (movie/titanic in http://example.com/movie/titanic?is=amovie). To fix the rule, you need to change the rule to:
RewriteRule ^movie/([a-z0-9]+)/?$ movie.php?name=$1 [L,NC]
The [L] flag stops rewriting for this round, the [NC] flag ignores case.
Besides that, you only need one RewriteEngine on, which needs to be above all rules you write. You can safely delete the second one.
You can put your .htaccess into main Directory:
RewriteEngine On
RewriteRule ^movie/([a-zA-Z0-9]+)(/)$ movie.php?name=$1 [L]
Or in movies/ directory:
RewriteEngine On /movies/
RewriteRule ^([a-zA-Z0-9]+)(/)$ ../movie.php?name=$1 [L]
While movie.php is in main Directory located.
RewriteEngine On can by starterd only once per htaccess.
I have a script that was written using codeigniter.
When accessed using a subdomain http://name.domain.com/admin/ it works fine but I now need to have the script installed in a folder and I cannot access http://domain.com/name/admin/ i just get a 404
I would guess (but I could be totally wrong) that it is a .htaccess issue.
RewriteEngine on
RewriteCond $1 !^(index\.php|install|updates|backups|images|css|js|uploads|jPicker|ckeditor|kcfinder|qr|fancybox|test\.php|licence\.txt|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I would really appreciate any help to point me in the right direction so I can resolve this issue.
Thanks
{EDIT1}
With NO .htaccess file name.domain.com/, name.domain.com/admin & domain.com/name all work, it is only domain.com/name/admin that does not work.
When I add a .htaccess as above or the one in the second answer below the subdomain URL's still work but domain.com/name stops working and domain.com/name/admin continues not to work
You should exclude also your name folder on your .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|install|updates|backups|images|css|js|uploads|jPicker|ckeditor|kcfinder|qr|fancybox|test\.php|licence\.txt|robots\.txt|name)
RewriteRule ^(.*)$ /index.php/$1 [L]