I am asking question after so many attempts to do this. Found many results on this website but none of them worked for me.
I have a website built in PHP (no any CMS) that has URLS like
www.someweb.com/job_detail?job_id=this-is-my-job-no-1
www.someweb.com/job_detail?job_id=this-is-my-job-no-2
www.someweb.com/job_detail?job_id=this-is-my-job-no-3
I just want to convert all URLS like these
www.someweb.com/job_detail/this-is-my-job-no-1
www.someweb.com/job_detail/this-is-my-job-no-2
www.someweb.com/job_detail/this-is-my-job-no-3
Here is my .htaccess content:
DirectoryIndex index.php
RedirectMatch 404 ^/admin/$
RedirectMatch 404 ^/admin/uploads/$
ErrorDocument 404 /page_not_found.php
<Files index.php>
Order deny,allow
deny from all
allow from all
</Files>
Have tried many ways but no one solved my issue. Please help me getting fine solution. Thanks.
Add this rules:
RewriteRule job_detail\/([\w\-]+) job_detail?job_id=$1
Redirectmatch 301 job_detail?job_id=(\w+) job_detail/$1
Related
I want to make a redirection from an old URL https://www.mywebsite.eu/en/form/emsos-2017/ to the homepage https://www.mywebsite.eu/.
I do not have access to the webserver but I know that the language prefix (in this case /en) is managed by the CodeIgniter framework.
mod_alias and mod_rewrite are enabled.
So I already tried that but none worked.
Redirect https://www.mywebsite.eu/en/form/emsos-2017 https://www.mywebsite.eu
RewriteRule ^emsos-2017/ https://www.mywebsite.eu [R=301,L]
RedirectMatch 301 ^/emsos-2017$ http://www.mywebsite.eu
I know that the .htaccess is read because when I make a typo I have an Internal Server Error.
I also tried to redirect 404 error but this is not working.
ErrorDocument 404 https://www.mywebsite.eu/404/
You need to give full URI without domain name in pattern of RedirectMatch.
Try this rule before any other rule in site root .htaccess:
RedirectMatch 301 ^/[a-z]{2}/form/emsos-2017/?$ /
I am migrating my site from Wordpress to Jekyll and I would like to keep the URLs working. My idea was to use a .htaccess file for this and to place it in the root of the site. But unfortunately after trying several tutorials and generates it doesn't seem to work.
The old URLs have the following format
http://example.com/index.php/2016/05/07/title-of-the-blog-post/
The new URLs have this format:
http://example.com/2016/05/07/title-of-the-blog-post.html
Among others I've tried this example which looks good to me, but it actually casues all pages on my site to display an error message :)
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^index.php.*$ http://example.com/ [R=301,L]
I think that should take all URLs that start with example.com/index.php and make them start with example.com/, but apparently that is not the case.
To redirect
http://example.com/index.php/2016/05/07/title-of-the-blog-post/
to
http://example.com/2016/05/07/title-of-the-blog-post.html
you can use the following rule :
RewriteEngine on
RewriteRule ^index\.php/(.+)$ http://example.com/$1.html [NE,L,R]
or alternatively you can use mod_alias like that:
RedirectMatch 301 ^/index\.php/(.+)$ http://example.com/$1.html
I have jpg urls like these:
http://domain.com/members/content/upload/temp/1600watermarked/photo.jpg
http://domain.com/members/content/upload/test-123/1200watermarked/photo.jpg
http://domain.com/members/content/upload/random/1800watermarked/photo.jpg
In the folder content I have an htaccess file with this in there:
<FilesMatch /watermarked/.*>
Order Allow,Deny
Deny from all
</FilesMatch>
But that doesn't seem to work in blocking any jpg urls with the word "watermarked" in them. Any suggestions?
Well after some more experimenting I got this:
RewriteCond %{REQUEST_URI} ^(.*)watermarked(.*)$
RewriteRule ^(.*)$ http://domain.com/forbidden.htm [R=301,L]
It's not exactly a forbidden error but it works better in my case since I can redirect them to a page to upgrade their accounts to see the blocked content.
I am doing a set of 301 redirects in Drupal.
I am using a standard method in the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
</IfModule>
but the return url ends up with "?q=user" and stops it working. eg:
http://thesitedomain.com/about?q=user/about
I am not great at htaccess redirects (obviously) and I am no Drupal expert at all.
Also, if you know of a comprehensive htaccess rewrite resource I would much appreciate reading hat.
You will need to use mod_rewrite instead to strip out existing query string:
RewriteEngine On
RewriteRule ^user/testimonials/?$ http://thesitedomain.com/testimonials? [L,NC,R=301]
RewriteRule ^user/contact/?$ http://thesitedomain.com/contact? [L,NC,R=301]
Take note of trailing ? in target that strips out existing query string.
I can't speak to drupal, but I know you don't need to enclose those redirects in the <IfModule mod_rewrite.c> tags, since they don't use the RewriteEngine, the below would suffice:
Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
Are both urls in the same drupal? Or are you moving from a different site?
I mean:
/user/testimonials
http://thesitedomain.com/testimonials
Maybe what you need is to add an url alias for /user/testimonials like /testimonials
See under admin at /admin/config/search/path in drupal 7.
Using .htaccess file is not a good practice, because, in some updates you have to update the .htaccess file too.
You can try GlobalRedirect module to manage your redirects.
I am trying to use an htaccess redirect, and for some reason when I try to redirect the user, instead of going to page.html, it tries to go to page.htmlpage.htmlpage.htmlpage.html and it just keeps on repeating it. Anyone have any clue what I am going wrong?
Here is my htaccess file:
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName 2enetwork.x10hosting.com
Options All -Indexes
ErrorDocument 401 /error/401.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
Redirect / http://2enetwork.tk/under_construction.html
#RewriteEngine On
#RewriteRule ^(.*)$ ./under_construction.html [L]
Oh, and also, it will give me a 403 error and underneath that it says and addition 302 error was found. If I comment the Redirect / http://2enetwork.tk/under_construction.html, it works fine. There is nothing wrong with the site, and I can see the under construction page fine.
Ok, I figured out why. When I sat there and tried to rediret my site, I redirected the whole site to uc.html (under_construction.html), and uc.html is included in the rest of the site, so it would then try to redirect to uc.html again, and again, and again in a never ending loop. So, my new question is, How do I prevent this from happening? Is there a way I can redirect my whole site minus uc.html?
Anything more complex than a brute force "go there" needs mod_rewrite.
This hasn't been tested, but...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !under_construction\.html$
RewriteRule ^(.*)$ ./under_construction.html [L]
This RewriteCond line tells it to rewrite all requests except ones for files named under_construction.html*.
* Techinically, all files that end with the string "under_construction.html".