I'm trying to rewrite an url like this:
www.mywebsite.com/product/a-product-name-here/92341
to
www.mywebsite.com/our-products/a-product-name-here/92341
I'm using following rewriterule:
RewriteRule ^product/(.*)$ our-products/$ [R=301,L]
And according to this online tool it should do the trick. I've put this online, but it didn't affect anything.
AllowOverride is active on my host.
My folder structure is like this (tried the rewrite rule in both of the 2 .htaccess's):
UPDATE
This is the .htaccess content in the folder Corporate
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /corporate/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /corporate/index.php [L]
</IfModule>
# END WordPress
And this is the content of the .htaccess file in the product folder:
AddDefaultCharset utf-8
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+) index.php?a=$1 [nc]
Alright, as far as I understand, your problem can be divided into two parts.
Redirect public URL
You want the public URL example.com/product/foo-bar/1234 to be redirected to example.com/our-products/foo-bar/1234. This can be achieved with the already posted rule by anubhava, slightly modified to only match numbers:
Put it in your root .htaccess, besides index.php.
RewriteRule ^product/((.+)/(\d+))$ /our-products/$1 [R=301,L]
Map external URL to script, internally
Then, the external URL is example.com/our-products/foo-bar/1234, which does not physically exist on the server machine and therefore fails with a 404.
So you'll have to map it to the script containing the actual logic.
RewriteRule ^our-products/(.+)$ /product/index.php?a=$1 [L]
This is assuming that your script will accept the a parameter.
Your .htaccess files, after the changes
This is the .htaccess content in the folder Corporate
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^product/((.+)/(\d+))$ /our-products/$1 [R=301,L]
RewriteRule ^our-products/(.+)$ /product/index.php?a=$1 [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /corporate/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /corporate/index.php [L]
</IfModule>
# END WordPress
And this is the content of the .htaccess file in the product folder:
AddDefaultCharset utf-8
Options +FollowSymlinks
Related
I am trying to shorten my website url of a newly added page event like
mysite.com/asoebi/myevent instead of mysite.com/asoebi/index.php?event=myevent
but every time i try to change my .htaccess file it give an error
here is .htaccess code
<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/(\w+)$ ./index.php?event=$1
</IfModule>
You have to enable mod_rewrite in apache for this to work.
Put this one in the .htaccess file in the /public_html/asoebi/ folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /asoebi/
RewriteRule ^(.*)$ index.php?event=$1 [L]
</IfModule>
Also remove the last rewriterule from the main htaccess file you posted above
I am using this htaccess for my application.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any URL I will type in my browser, if the respective file doesn't exist, it will open the index.php.
The problem is I have many applications like this installed on the same domain.
For example, the root contains an index.php file and a htaccess like above.
I have also, /store, which contains a index.php file and a htaccess like above, too, but when I access /store/something it opens the index.php of root (not the correct /store/index.php
How can I solve this problem (how to make the htaccess of root to not override the htaccess of /store)? Thanks!
You can have a skip directory rule to skip all the directories:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# skip index.php and some directories
RewriteRule ^(store/|site1/|site2/|index\.php$) - [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Here is my .htaccess which i have default in laravel it helps me to prevent typing public/index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
So, if i need to access
localhost/public/index.php/home
localhost/public/index.php/login
It is enough to me to type
localhost/home
localhost/login
I want to make exception to for few directories such as 'testproject' and 'betaproject' i.e., where i will have a regular php or html directory or i will have another fresh project and it will have same .htaccess also.
How can i modify my .htaccess file to make it possible.
So that if i want to access
localhost/testproject/public/index.php/home should be accessible by localhost/testproject/home
In your root .htaccess have this rule to skip 2 directories:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(testproject|betaproject)/(\w+)/?$ $1/public/index.php/$2 [L,NC]
Make sure this rule is very first just below RewriteEngine On line.
I'm looking for a way to have the URL
site.com/collection/name
serve the content that is actually located at...
site.com/collection/?collection_name=name
The website is running on WordPress, and is currently using the default .htaccess rules located in the root:
# 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
Because it's on WordPress, it's currently looking for a page /collection/name that doesn't exist, and produces a 404 error.
There should be an index file under the folder "name"
If so, you can try this:
RewriteEngine On
RewriteBase /
RewriteRule ^/$ /collection/name/index.php
RewriteRule ^([a-zA-Z0-9_-]+)/$ /collection/?collection_name=$1
This is a generic rule that works in many similar occasions. Modify it to suit your website...
Please I need a help. I am working on a site and wants to redirect all requests to an index file while allowing access to images, css, javascripts and other documents that are not php scripts. I am working on a local server (WAMP). The problem I have is that it redirects all requests to the index file including images. Below is my htaccess rule.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myapp
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/([^/]+)/?$ app/$1-$2/$3 [R=301,L]
RewriteRule ^(.*)$ index.php [L]
</IfModule>
Is this not what you're aiming for?
RewriteRule ^(.*\.php)$ index.php [L]
You should also escape those slashes in your first rewrite rule
Thanks I have figured it out, I just modified the moved the first rewrite rule above the rewrite condition and it now working fine.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myapp
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/([^/]+)/?$ app/$1-$2/$3 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>