How to do a mod rewrite for this? - php

Currently, when my users are buying from my shop it will go to:
http://localhost.com/shop/index.php?shopid=1&item=2
How would I make it to where it would be like
1 being shopid, 2 being item.
http://locahost.com/shop/1/2

Try the following in your .htaccess file
RewriteEngine On
RewriteRule ^shop/([^/.]+)/([^/.]+)?$ shop/index.php?shopid=$1&item=$2 [L,NC]
Hope it works.

This option is in your httpd.conf file.
change it from
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Related

phpmyadmin giving 500 error after update the apache2.conf

I am using Linux mint. I am working in a Wordpress, It was not possible navigate a page. I got a answer from a source to change the apache2.conf file like bellow
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
But for me the phpmyadmin is not working after this change. For that problem i go for this
Adding
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
in the phpmyadmin.conf file. But still it is working. Is there are anything i have left.
Thanks in advance.

enable htaccess apcahe on ubuntu

I have an apache server on ubuntu where i have a virtual host that points to my site. Problem is my htaccess not functional.
In my apache2.conf file i have something like
<Directory />
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
if i change AllowOverride for "www" directory htaccess is functional but i get 403 forbidden error. please guide me what i am doing wrong.
regards.
You have to set AllowOverride to all like this.
<Directory "/var/www">
AllowOverride All
</Directory>
After that if you are facing forbidden error then probably you have error in htaccess file. Remove the code in htaccess file then start writing code block by block. By this you can debug error in htaccess file. For more info, you can have a look on this.
https://askubuntu.com/questions/429869/is-this-a-correct-way-to-enable-htaccess-in-apache-2-4-7-on-ubuntu-12-04#answer-429931

.htaccess ErrorDocument 404 not redirecting

I have tried to create a custom page for the 404 errors to go to, these are the settings in my apache2.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/html>
options Index FollowSymLinks
AllowOverride All
Require all granted
</Directory>
and this is my code in the .htaccess file
RewriteEngine On # Turn on the rewriting engine
ErrorDocument 404 /404.php
RewriteRule ^ls/(\w+)/?$ Pages/misc/profile.php?ss=$1 [NC]
however when I test a page that doesn't exist and it 404s, it doesn't redirect at all to 404.php. For instance if I try a random page like asdf.html, it doesn't show the custom 404 page or even say can't find 404.php, it says it can't find asdf.html which means the redirect never takes place. Can anyone shed some light on why it doesn't redirect?
Thank - you!
p.s. my website resides in /var/www/html for reference

How to rewrite URL without .htaccess?

I've been reading up on this on the web, but still could not figure out how to implement it properly. I'd greatly appreciate if you could help me understand how to make url rewrite work without .htaccess.
To check if mod_rewrite is enabled, I ran command ~# sudo apachectl -t -D DUMP_MODULES. It produced, among others the following module: rewrite_module (shared). I don't know if it is the same as mod_rewrite?
Folder /etc/apache2/mods-enabled/ has file rewrite.load
I'm not clear which file exactly I should add rewrite rules to?
File httpd.conf located in /etc/apache2/ is empty. However there's a file named 000-default located in /etc/apache2/sites-enabled/ and it looks like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I'm not clear at all where I should add rewrite rules. I tried adding them to this 000-default file into <Directory /var/www/> section, but it did not work.
You put the rewrite code in the directory block where you're have the .htaccess file (if you use them). For example if /var/www is your docroot, you could put it their:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
</Directory>
If you are using apache 2.2.16 or newer, use
FallbackResource /index.php

.htaccess not triggered

So I have the following .htaccess in my /var/www/site
RewriteEngine on
RewriteRule ^([^/]+)/?$ parser.php?id=$1 [QSA,L]
I have allowed override in my vhost:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/site>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
UPDATE:
Now I got it to work, however when I visit site.com, it also redirects me to this parser.php, in which I don't want as this is my homepage.
My homepage should be redirected to index.php and if I do mysite/NASKDj, it should be redirected to parser.php?pid=NASKDj. How do I fix this?
You have 'AllowOverride None' in the '/var/www/site' directory - this will overrive the one specified in the '/' directory. If your site is in /var/www/site you need to change This one to All too.
I just saw AllowOverride None in your <Directory /var/www/site>...</Directory>, So?

Categories