Why am I getting a 404 server error htaccess rewrite rule? - .htaccess

Im trying to add a simple rewrite rule so that any request sent to /api/v1/ will be processed by /api/v1/api.php
Currently it does a 404 on my when I try and run the example method /api/v1/example
Im following this tutorial but little confused where to put my rewrite rule in my current htaccess file.
What I have so far in my htaccess file is:
# 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]
RewriteRule ^api/v1/(.*)$ api/v1/api.php?request=$1 [QSA,NC,L] # 404
</IfModule>
# END WordPress
Ive tried the wordpress method but that doesn't work either
add_rewrite_rule('^api/v1/(.*)$','api/v1/api.php?request=$1','top');
any help would be greatly appreciated.
Cheers :)

I'm doing similar - so in my /path/to/doc/root/api/v1/.htaccess I have
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /api/v1/index.php [L]
This ONLY catches requests in the /api/v1/ directory or lower, so the rest of my stuff still generates normal 404 errors, etc.

Related

301 Redirect from dynamic ASPX

I have a daunting problem with dynamic redirects that I have to do on WordPress website that was before an aspx website.
I am looking for advice for a week now and tried almost everything with different outcomes but none proved successful.
I need to redirect complex URLs such as:
/Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default.aspx?SortField=ProductName%2CProductName
to something simple like
http://domain.com/folder/
I've used number of ideas including loads from StackOverflow but none seem to tackle this specific example. Using standard Redirect 301 rule will work for as long as I don't have ? in the link. I understand this is beyond the scope of Redirect 301 and I need to use RewriteRule.
I tried this (got this from the excel spreadsheet for dynamic urls redirection):
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://domain.com/folder/? [R=301,L]
But still on entering the url it yields 404 page.
Here's my .htaccess:
## 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]
## messing up
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://domain.com/folder/? [R=301,L]
</IfModule>
Do I place it correctly? Is the code right? I would appreciate any ideas and clues.
Thanks a million
I have solve the mastery. The code was good just the placing was incorrect. After dozen tries and errors I found the correct formula. I had to amend placing of my redirect rule. Here is how it looks:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://doamin.com/folder/? [R=301,L]
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default.aspx?SortField=ProductName%2CProductName
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Forbidden: Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request

Hi i have this folder on my server and it is clients/nannyshareaustralia and im using a codeigniter framework i already set up the config.php in the base url too. And im adding also for the htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|images|js|assets|css)
RewriteRule ^(.*)$ /clients/nannyshareaustralia/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /clients/nannyshareaustralia/index.php?/$1 [L]
and when i run it to the browser this is what it goes
Forbidden
You don't have permission to access /clients/nannyshareaustralia on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
can someone help me figured this out? Any help is muchly appreciated
Please try this Following code write in your .htaccess file
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
RewriteEngine On
RewriteBase /clients/nannyshareaustralia
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|images|js|assets|css)
....
Added a RewriteBase rule to your .htaccess granting that mod_rewrite is enabled on your server.
note
If you access the directory like www.domain.com/clients/nannyshareaustralia you must add a RewriteBase to the .htaccess
But if a url/domain is pointed at the folder clients/nannyshareaustralia there is no need for the RewriteBase.

Redirecting a web page to a subdirectory

I want to redirect the page http://www.unived.in/ to http://www.unived.in/aboutus/.
I tried lots of plugins but the page still isn't redirected. In fact I have tried changing .htaccess but it still doesn't redirect properly. Sometimes it displays error 500.
Here is my .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond /home/unived/public_html/wp-content/sitemaps%{REQUEST_URI} -f
RewriteRule \.xml(\.gz)?$ /wp-content/sitemaps%{REQUEST_URI} [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
What do I need to do to make the redirection work?
Read this tutorial to learn more about mod_rewrite: http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
It's very detailed, and should help you accomplish your goal.

htaccess rewrite rule blog links

I have been using htaccess to remove rewrite certain URLs, however I am looking at something a little more complicated at the moment.
Our website blog (WordPress) used to have links like this:
​/blog​/postname/1387
However after redoing the website our links are now currently just
/postname
Would it be possible to redirect any uses from ​/blog​/postname/1387 and get rid of the blog and number at the end via htaccess so it just contains the postname? At the moment I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^blog/(.*)/.*$ $1/
</IfModule>
Would love to hear any hints or tips, as this is not actually doing any redirecting, what am I doing wrong?
Let's just do a little cleanup:
<IfModule mod_rewrite.c>
#Turn on the RewriteEngine
RewriteEngine On
#Rewrites are all relative to /
RewriteBase /
#Explicit - If the request is for index.php, do nothing.
RewriteRule ^index\.php$ - [L]
#Conditional – Unless the file or directory specifically exists,
#If the request is for the old style blog URI, redirect to new style and stop.
#Otherwise, redirect to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/.*$ $1/ [R=301,L,QSA]
RewriteRule . /index.php [L]
</IfModule>

htaccess mod_rewrite - reroute all urls to index except /admin

I'm setting up a small set of rewrite rules in an htaccess file, where I want every url to go to a index.php file except for /admin which I want to redirect to admin.php. Not very familiar with mod_rewrite or regexp unfortunately.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin.php [L]
RewriteRule . /index.php [L]
</IfModule>
This gives me an internal server error (not saying 500). Removing or uncommenting the admin rewrite makes it work.
The conditions need to be applied to the index.php rewrite rule, otherwise it causes a redirect loop. A RewriteCond only gets applied to the immediately following RewriteRule so the rule that routes everything to index has no conditions. Try just rearranging the lines:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^admin$ admin.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Resources