Here's my htaccess file at the moment:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /blog/
ErrorDocument 404 /blog/404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ post.php/$1.html
RewriteRule ^index$ index.php
RewriteRule ^archives$ archives.php
RewriteRule ^about$ about.php
RewriteRule ^search$ search.php
RewriteRule ^feed$ feed.php
At the moment if I go to domain.com/blog/*.html, it is redirecting (in the background) to domain.com/blog/post.php/*
I would like to almost copy this but I'm not sure about all this regular expression stuff.
I would like to be able to also go to domain.com/blog/admin/* and for it to redirect (in the background) to domain.com/blog/admin.php?p=*
If you guys could help me out, I would really appreciate it!
Thanks
Something like:
RewriteRule ^/?admin/(.*)$ admin.php?p=$1&%{QUERY_STRING} [L,NC]
Will do the trick.
This is done very quickly and it isn't tested but it gives you the idea. You put this above:
RewriteRule ^(.*)\.html$ post.php/$1.html
Edit: Took out the rewritecond since I just realised it is useless
Edit: Added query string too since you are actually converting the _GET now.
Add multiviews to the first line of your .htaccess:
Options FollowSymLinks MultiViews
Then, restart apache. It should point admin to admin.php.
Note: Don't have multiple files in the same directory with the same name and different extension.
http://httpd.apache.org/docs/2.2/mod/mod_negotiation.html
Related
Long story short, I updated an e-commerce website but had to install the new static CMS system into a sub-directory (/wear). The main e-commerce store is still sitting in the root directory (/), and due to the large amount of products and SEO impact, I need to leave it there.
I would like to setup a requests for just index.php to redirect to /wear/
At the same time, if there is a request for index.php?XXXXX I would like it to still use the index.php file.
I've tried using the following .htaccess code but it's redirecting everything. Can anyone help me with this? I apologize for asking this as I know there are multiple threads, but none seemed to provide a good answer.
Attempt 1
RedirectMatch /index.php https://domain/wear/
Attemp 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wear/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The issue comes from your RewriteBase. When setting it up to /wear/, RewriteRule ^index\.php$ - [L] actually translates to RewriteRule ^wear/index\.php$ - [L] which is not really what you want.
I would try something like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ /wear/ [L,R=301]
What it does is: check that the query string is empty, and if it is, redirect index.php (at the beginning of the request URI, so /index.php only) to /wear/
You will also need to make sure than mod_rewrite is active.
To do so, you can remove the <IfModule mod_rewrite.c> and </IfModule> parts. If mod_rewrite is not available, it will trigger an Error 500 as the RewriteEngine command will not be recognised.
Before I start, I'd like to say that I did search for topics similar to my problem and tried all solutions provided, but my problem still persists, so I had to post my own question.
Anyway, inside our wordpress site, we have a page called site.com/shops and we want to put a parameter to it. After that we want to use a rewrite rule so that site.com/tx will load site.com/?pagename=shops&state=tx. We put this on our .htaccess:
RewriteRule ^tx(/)?$ index.php?pagename=shops&state=tx[L]
For some reason this doesn't work like we intended. I checked to see if index.php was the problem by changing it to
RewriteRule ^tx(/)?$ test.php?pagename=shops&state=tx[L]
That worked, so I believe the problem is that it doesn't work if index.php was used. How do I make it work using index.php? TIA.
Replace .htaccess code with below code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress_test/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress_test/index.php [L]
</IfModule>
i hope it's works
I have wordpress installed and in the root i created a folder and put an .htaccess inside to redirect to another web page without changing the URL.
This was working fine until i move to another server (the older one was just horrible) and now it just not working.
This is code that i was using:
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/conexionalam
RewriteRule ^(.*)$ http://nuevoserver.breinguash.com/$1 [R=301,L,P]
and is no longer working, show me this:
looking for internet i have tested some other codes:
1-
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/conexionalam(/.*|)$ nuevoserver.breinguash.com$1 [L,NC]
2-
RewriteEngine ON
RewriteRule ^/(.+) http://nuevoserver.breinguash.com/$1 [R,L]
This two show me this:
3-
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://nuevoserver.breinguash.com/$1
This one redirect me to http://nuevoserver.breinguash.com/index.html
I realized that if i took off this '[R=301,L,P]' at the end of the first code, it works but changing the URL and i don't want tat.
Thanks in advanced!
EDIT:
By the moment im using this code:
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/conexionalam
RewriteRule ^(.*)$ http://nuevoserver.breinguash.com/$1
Its redirects but change the URL = /
but for now does not affect google analytics.
if i change or add something to the code it does show me the errors from above. i really doesn't understand why it does that.
SOLUTION
Well it seem that i cant redirect between domains/subdomains without changing the URL just like that, i have to do it with proxy, so the solution was:
Enable proxy and proxy-http on apache.
Use the P flag for RewriteRule
So right now i'm using this code and it works perfectly:
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/conexionalam
RewriteRule ^(.*)$ http://nuevoserver.breinguash.com/$1 [R=301,L,P]
Give this a shot in your .htaccess file...
RewriteEngine On
RewriteBase /
RewriteRule ^conexionalam(.*)$ http://nuevoserver.breinguash.com/$1 [L,R=301]
This should redirect you to http://nuevoserver.breinguash.com when you go to /conexionalam from your main domain.
Could someone please tell what I am doing wrong. I have searched through lots of posts here and elsewhere about doing this.
Just want to make localhost/index.php?page=somepage look like localhost/somepage
Here is what I have so far:
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z\-]+)$ index.php?page=$1
</IfModule>
Not getting any errors, but it's not dong anything actually. Maybe I have the code right but just can't do this on my system. But would like a pro opinion.
Thank you.
Maybe worth mentioning: have htaccess file in root dir, all pages are in a folder named "pages" and all end in .htm
That looks like it takes a request like: localhost/somepage and internally rewrites it to localhost/index.php?page=somepage, which is really what you want. But it doesn't address if someone tries to go to localhost/index.php?page=somepage. In order to address that, you don't want to rewrite URL's, you want to redirect the browser to a new URL:
RewriteCond %{THE_REQUEST} \ /+index\.php\?page=([^\ \&]+)
RewriteRule ^ /%1? [L,R]
Okay I'm trying to use Lando (landocms.com) and I'm trying to get the pretty urls option to work.
Basically by default Lando creates link like: domain.com/index.php/page. Supposedly, there is a way to remove the index.php so the links become: domain.com/page. I have created an .htaccess as directed, however it does not work.
Here is the .htaccess I am using:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I have tried alot of variations, /index.php/, index.php? and plenty more but none work. According to HostGator everything should be fine. Any thoughts? I think I'm going crazy haha.
Thanks!
Rewriting for a CMS is a two-tier approach. First, you need to set your .htaccess (I have put a safer one here for you):
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php [QSA,L]
Then, LandoCMS allows you to remove the index.php from the generated addresses, by means of turning on the appropriate setting in the administration panel. See this link for more information.
If the .htaccess content I've given you doesn't work, then simply use the one that the CMS has given you.
You want to remove the index.php part from any URL, but process the incoming, friendly URLs through index.php nevertheless
RewriteEngine On
# remove index.php and redirect client
RewriteCond %{ENV:REDIRECT_SEO} ^$
RewriteRule ^/?index.php/(.*) /$1 [R,L]
# process friendly URL
RewriteCond %{REQUEST_URI} !^/index.php/
RewriteRule .+ /index.php/$0 [E=SEO:1,L]
The environment setting E=SEO:1 prevents an endless loop.