I have looked online for a solution here but I am struggling to find the right answer. Hopefully someone can help.
I have the following translation link on a webpage like so, Translate but the actual path was on my server is /_translations/de/about/.
Currently, the link goes to a 404 error and of course works if I prepend the url to the actual path.
What would be the rewrite rule for this?
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*)$ /_translations/$1/$2 [L]
Related
I'd like to ask if it's possible to use a dynamic url and GET at the same time.
Let's say my current dynamic url is: https://yourdomain.com/blog/this-is-a-title
Would it be possible to make this work too: https://yourdomain.com/blog/this-is-a-title?action=delete
RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?id=$1
The dynamic url mentioned first works fine, but I want to make the second work as well.
This is my .htaccess - hope it helps.
PS: I know that the regex in my htaccess isn't correct, it's just an example.
Have your .htaccess Rules file in following manner. Please make sure that your htaccess Rules file is present in root folder(where blog and htaccess both are residing in it; htaccess shiouldn't be inside blog folder; should be place same folder with it). Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Newly added rules here...
RewriteBase /blog/
RewriteCond %{THE_REQUEST} \s/blog/(?:[^?]*)?action=(\S+)\s [NC]
RewriteRule ^ index.php?action=%1 [L]
##Old Rules OP's htaccess ones.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ index.php?id=$1
I have to do a very specific url redirect using mod_rewrite within an .htaccess. Below is a url which has to map to the url below it:
m.example.com/123456/123456-product-name/
This needs to map to the following:
m.example.com/product-name/123456
I'm still getting to grips with regex and url rewrites and I've spent a good couple of hours trying to get this right. Can anybody help!?
Thanks in advance
You can do that. in root .htaccess:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^\d+/(\d+)-([^/]+) /$2/$1 [R=301,L]
Or just [L] (and not [R=301,L]), if you do that without redirection.
I've searched stackoverflow and numerous websites for an answer to this. So please don't shoot me if it's already been answered on stackoverflow. I am stuck.
I just need a simple redirect where anything after my website name is put into a querystring of $target except for when a path is included in the url.
It doesn't work when a path is given.
eg)
mysite.com.au/home to mysite.com.au/?target=home
mysite.com.au/home/ to mysite.com.au/?target=home
mysite.com.au/home/something to mysite.com.au/home/something
mysite.com.au/home/something/ to mysite.com.au/home/something
mysite.com.au/home/something/file.php to mysite.com.au/home/something/file.php
The below in my .htaccess file. It only works for condition 1 above.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ?target=$1
Can somebody show me a better/proper way for url redirects or know how to do this?
I don't want to use specific 301 redirects.
Thanks for any help you can provide.
You can put this code in your htaccess (which has to be in document root folder)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /?target=$1 [L]
Due to a mistake in an article, one of our links was added as example.com/index instead of example.com/index.html or simply example.com. We have no access to the article nor possibility to change the link at this moment.
I was thinking to add a .htaccess rule and redirect http://example.com/index to http://example.com. I found solutions for redirecting subdirectories and files but cannot find a simple solution that works only for http://example.com/index (and not as a complete subdirectory) some other solutions failed as well.
If requesting /index is wrong it should result in a page not found. So see how this works for you in your .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ / [R=301,L]
I used this code in my .htaccess to rewrite my urls which is like this:
www.example.com/subcategory.php?subcat=my-test
to
www.example.com/my-test
.htaccess code I used:
RewriteEngine on
RewriteCond $1 !^(subcategory\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ subcategory.php?subcat=$1 [L,QSA]
My problem is whenever I access the url not pertaining to my subcategory.php file like contactus and aboutus, the .htaccess file will somehow put me to subcategory.php file which is not what I want. I want my contactus be handled by contactus.php and aboutus with aboutus.php.
I know that there is something wrong with my .htaccess file but I couldn't fix it by myself for I am not so familiar with the .htaccess coding.
Any suggestion would be greatly appreciated.
Thank you very much!
You are rewriting all requests to subcategory.php. There is no way for .htaccess to tell whether /xxx is a subcategory or some different page, so you could redirect it to a different script.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Use this code snippet instead of yours and move all the "routing" logic to PHP. In PHP, you can find out whether /xxx is a subcategory, a contact page, an article or something else and use a script suitable for that kind of database record.
You will find the requested URL in $_SERVER['REQUEST_URI'].