So my problem is that I have this running in a sub-directory and there are a couple problems...
When I add the 301 redirect I get a 500 error
I cannot get "page" removed from the URL (http://174.136.15.245/~clubz/test/page/about-club-z-tutoring-test)
Here is my code:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
# RewriteRule (.*) http://174.136.15.245/~clubztutors/test/ [R,L]
RewriteBase /~clubz/test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ page.php?/$1 [R=301, L]
# RewriteRule ^page.php?p=$1 page/([^/.]+)/?$ [R=301, L]
# This works but add "page" directory
RewriteRule ^page/([^/.]+)/?$ page.php?p=$1 [L]
</IfModule>
I did look through some other solutions here but I still could not get this to function exactly the way I needed. Any insight would be appreciated.
Jackpot! Well, at least on getting page removed from the URL:
RewriteRule ^([^/.]+)/?$ page.php?p=$1 [L]
The redirect still doesn't work but it would be nice to have. For now I'll run with this.
Related
This might be something simple, but I spent days on it, without results.
My website home page URL by default is
https://rezume.am/index.php?controller=pjLoad&action=pjActionJobs
I want to see https://rezume.am/ instead.
When I added the following rule in .htaccess file:
RewriteRule ^()$ index.php?controller=pjLoad&action=pjActionJobs$1
Things worked, but filters on the left got broken.
Here is my whole .htaccess content:
#Redirection code starts
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Redirection code Ends
RewriteEngine On
RewriteRule ^(.*)-(\d+).html$ index.php?controller=pjLoad&action=pjActionView&id=$2
RewriteOptions inherit
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase //
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . //index.php [L]
#RewriteRule ^(.*)$ index.php/$1 [PT,L]
RewriteRule ^()$ index.php?controller=pjLoad&action=pjActionJobs$1
</IfModule>
Could anyone please advise a better rule to skip controllers and actions and see just domain?
i'm using .htaccess to create clean urls.
here is a piece of .htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^posts/page/([0-9]+)/$ posts.php?page=$1
RewriteRule ^posts posts.php
it works fine but problem is both urls work!
is there a way to only make site.com/posts/ work and return 'not found' on site.com/posts.php(or redirect to site.com/posts/)
think i read somewhere two urls for the same page is bad for seo.
You can create a rewrite rule that returns 404 HTTP code on every ".php" URL :
RewriteRule .*\.php$ - [R=404]
This is working fine for me. Hope it will work fine for you as well.
RewriteEngine On
Options -Multiviews
#For rewriting request to posts.php
RewriteCond %{REQUEST_URI} ^/posts/?$
RewriteRule .* /posts.php [L,END]
#For returning 404 on directly accessing /posts.php
RewriteCond %{REQUEST_URI} ^/posts.php$
RewriteRule .* - [R=404,L]
To redirect /posts.php to /posts you can use this
RewriteEngine on
RewriteCond %{THE_REQUEST} /posts\.php [NC]
RewriteRule ^ /posts [NE,L,R]
#Your other rules
If you want to redirect the orignal request to 404 , change the RewriteRule line to this
RewriteRule ^ - [R=404,L]
I have tried below code to redirect non www to www url in wordpresss but its not working .
Please check below code is right one?
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.ie[nc]
RewriteRule ^(.*)$ http://www.domain.ie/$1 [r=301,nc]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The proper .htaccess rule should be:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Keep in mind that Wordpress has own rewrite rules installed in .htaccess file, do not remove them (they are placed between comments lines # BEGIN WordPress and # END WordPress)
According to the manual at https://www.ostraining.com/blog/wordpress/non-www/
The correct code is
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Otherwise there may be a other problem that you can reprocedure from the error logs
I am hoping that you can help me with the htaccess rewrite rule below.
# BEGIN WordPress
# WPhtc: Begin Custom htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have recently changed my wordpress site from http to https... The problem is that old url's redirect to the domain name instead of the https version of that page
eg
if I access the following page https://domain.com/test/testing/ it works 100%, now if I change the https part to http then the page redirects to https://domain.com instead of to https://domain.com/test/testing/ how do I fix it so that if you go to the old version page http://domain.com/test/testing/ (the not https version) that it redirects to https://domain.com/test/testing/ instead of just the domain name https://domain.com
You have to find a workaround for %{REQUEST_FILENAME} since this only represents the file that is accessed. But you obviously want to access the SSL vHost.
So you might hardcode the https into your .htaccess.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
This might help you alot. (found the code above there)
I've been struggling also with this issue and finally I found a solution for the home redirection and the wordpress in the same htaccess file, and finally it also works for old http links, redirecting to https:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tried your solution. It worked well, but if you do that you'll need to manually change all your internal links.
This works better ;)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
I use this .htaccess for wordpress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have a website and i want to make it always show as www.mysite .com i put that code in .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
now the url shows as www but the website is not shown the browser said "This webpage has a redirect loop"
Note: .htcaccess do not have any code but this few lines i wrote
does i did anything wrong or i miss something??? please help
Edit:
before I add the above code the .htaccess had the following code but not direct to www i remove it :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule (.*) $1? [R=permanent]
# END WordPress
could that be updated to solve my problem?
if you are doing it at windows server it will not work if it is window you have to create web.config file n for linux it should be .htaccess
Ok so Wordpress is also there. Make sure to do these 2 things:
Put your 301 rule above WP's rules i.e. just below RewriteBase line
Update WP settings to have your site address with www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
or
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]