Rewrite URL dont get values and error 404 - php

My Htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([0-9]+)&title=([^\s&]+)\s [NC]
RewriteRule ^ %2-%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+?)-([0-9]+)$ index.php?id=$2&title=$1 [L]
</IfModule>
I have in php urls as this :
index.php?id=34234&title=Hello_World&name=Mike
In the link i put this :
TEST
And i try get this url
http://www.test.com/34234/hello_world/mike
But all time give error as 404 error and i don´t know which it´s the solution for this, Thank´s in advanced

Your original URL has 3 path segments while your rule accepts only two. You need to fix your regex patterns
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([0-9]+)&title=([^\s&]+)&name=([^\s&]+)\s [NC]
RewriteRule ^ %1/%2/%3? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)/([^/]+)/(.+)/?$ index.php.php?id=$1&title=$2&name=$3 [L]
</IfModule>

Related

htaccess make dynamic url to static url

I have a URL like:
http://localhost/admin-s/index.php?m=user
However, I would like a URL like this:
http://localhost/admin-s/user
I try like this:
RewriteRule ^([a-z0-9]+).php$ index.php?nol&m=$1 [L]
RewriteCond %{QUERY_STRING} ^m=([a-zA-Z0-9]+)$
RewriteRule ^index.php$ user%1.php [L]
How to make it?
Hope this simple configuration will help you out. You can check this configuration here
This will redirect request of this pattern from http://localhost/admin-s/index.php?m=user to http://localhost/admin-s/user
Explanation:
1. If REQUEST_URI is /admin-s/index.php
2. If QUERY_STRING is m=someWords
3. Redirect to /admin-s/someWords
.htaccess
RewriteEngine on
Options -MultiViews
RewriteCond %{REQUEST_URI} \/admin\-s\/index\.php
RewriteCond %{QUERY_STRING} m=([\w]+)
RewriteRule ^(.*)$ /admin-s/%1? [R=301,L]
The question was answered here : How to turn dynamic URL into static URL
For your problem may be try following rules:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^admin-s/([^-]+) /index.php?m=$1 [R=301,QSA,L]
Let us know if it works
You can use the following rule in your root/.htaccess or /admin-s/.htaccess :
RewriteEngine on
#redirect /admin-s/index.php?m=user to /admin-s/user
RewriteCond %{THE_REQUEST} /admin-s/index\.php\?m=([^\s&]+) [NC]
RewriteRule ^ /admin-s/%1? [L,R]
#rewrite the new uri back to the orignal location
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:admin-s/)?(.+)$ /admin-s/index.php?m=$1 [NC,L]
Try below in your admin-s direcotry,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)$ index.php?m=$1 [L]

how to get rid of /index at end

I am using PHP codeigniter and chriskacerguis/codeigniter-restserver.
In log file I am seeing 404. because some how /index is getting append at end.
correct url is api/CurrentYear
DEBUG - 2016-02-02 02:14:48 --> UTF-8 Support Enabled
DEBUG - 2016-02-02 02:14:48 --> Global POST, GET and COOKIE data sanitized
ERROR - 2016-02-02 02:14:48 --> 404 Page Not Found: api/CurrentYear/index
Can anyone give me clue why /index is getting append at end or any solution.
my .htaccess look like this.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>
If you want to remove index.php from URL then follow code will surely works for you.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<IfModule mod_rewrite.c>
Please remove the index.php in codeIgniter Framework config file
$config['index_page'] = '';
And apply below htaccess coding
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule .* index.php/$0 [PT,L]
This code works for me
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !\.(gif|jpg|shtml|ico|swf|wav|mp3|less|cur)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?p=$1 [QSA]

.htaccess rule appending index.php instead of URI

My .htaccess looks like this..
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [R,L]
</IfModule>
I want to be able to redirect an URL that looks like this..
https://sub.domain.com/ZTHF76
to...
https://www.domain.com/members/invite/ZTHF76
But instead I am getting
https://www.domain.com/members/invite/index.php
I need to keep the first rule to remove index.php from the URI of the rest of the application.
Any help with this greatly appreciated.
You should reorder your rules and keep redirect rule before rewrite one:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

.htaccess Rewrite 505 Error Loop

I am trying to rewrite:
mydomain.com/category.php?id=cat
to
mydomain.com/cat
I have used the following .htaccess code but it keeps showing a 505 error:
RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?id=$1 [L]
I read on another page that it is because the page keeps looping, but I can't work out how I can fix the code.
Keep your rule like this:
RewriteEngine On
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /category.php?id=$1 [L,QSA]
Try this.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)/ category.php?id=$1 [L]
</IfModule>
You need to add RewriteCond to avoice rewrite for category.php
RewriteEngine On
RewriteCond %{REQUEUST_URI} !^ /category.php/(.*)
RewriteRule ^(\w+)/ category.php?id=$1 [L]
Ok this should work:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/category.php
RewriteRule ^(.*)$ category.php?id=$1 [R=301,L]
Demo: http://ht6.valhook.com/cat

Small error when using .htaccess for clean urls

I am using .htaccess to manage clean URL's but for some reason I get a 404 Not Found Apache error in some cases.
If a user goes to http://domain.com/profile/ everything is fine.
If a user goes to http://domain.com/profile they will get the error
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ /index.php?page=$1&cmd=$2 [L]
Try this:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# /profile/cmd
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ /index.php?page=$1&cmd=$2 [L]
# /profile
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /index.php?page=$1 [L]
</IfModule>
You can redirect the url with the url which has trailing slash using 301 redirect
Try the following along with your rewrite condition. This will redirect any url request to url with trailing slash. ex. http://domain.com/profile will be redirected to http://domain.com/profile/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
The rewrite rule you wrote requires one slash '/'.
Try this instead:
RewriteRule ^([^/]*)(/([^/]*))?$ /index.php?page=$1&cmd=$3 [L]

Categories